package com.cloudsigns.factorymanager2.engineering.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cloudsigns.factorymanager2.R;
import com.cloudsigns.factorymanager2.cusenum.CommonEnum;
import com.cloudsigns.factorymanager2.engineering.bean.EngineeringDailyFeedBackBean;
import com.cloudsigns.factorymanager2.engineering.bean.MediaBean;
import com.cloudsigns.factorymanager2.project.myinerface.ItemClickListener;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lenovo on 2018/7/21.
 */

public class PatrolCompletionOrderForManagerAdapter<T> extends BaseAdapter {
    private Context context;
    private List<T> datas = new ArrayList<T>();
    private LayoutInflater inflater;
    private ItemClickListener itemClickListener;
    private String tag = "";


    public PatrolCompletionOrderForManagerAdapter(Context context, String tag) {
        this.context = context;
        this.inflater = LayoutInflater.from(context);
        this.tag = tag;

    }

    public void setData(List<T> list) {

        if (null != list) {
            this.datas.clear();
            this.datas.addAll(list);
        }

    }

    public void setItemClick(ItemClickListener clickListener) {
        this.itemClickListener = clickListener;
    }

    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public T getItem(int position) {
        return datas.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.item_patrol_completion_order_for_manager, null);
            holder.rl_item = convertView.findViewById(R.id.rl_item);
            holder.tv_account_name = convertView.findViewById(R.id.tv_account_name);
            holder.img_statts = convertView.findViewById(R.id.img_statts);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }


        MediaBean bean = (MediaBean) datas.get(position);
        holder.rl_item.setTag(bean);
        holder.tv_account_name.setText(bean.getAssignReceiveAccountName());
        if(bean.isAllMediaSuccess()){
            holder.img_statts.setBackgroundResource(R.mipmap.icon_radio_green);
        }else{
            holder.img_statts.setBackgroundResource(R.mipmap.icon_radio_no);
        }


        holder.rl_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (null != itemClickListener) {
                    itemClickListener.itemClick(view, position);
                }
            }
        });

        return convertView;
    }

    private class ViewHolder {
        private View rl_item;
        private TextView tv_account_name;
        private ImageView img_statts;

    }
}
